//
//  PatientInfoCell.m
//  International_Hospital
//
//  Created by 统杰李 on 16/7/7.
//  Copyright © 2016年 LiYiLin. All rights reserved.
//

#import "PatientInfoCell.h"

@interface PatientInfoCell ()

//用户头像
@property (nonatomic, strong)UIImageView *userImageView;
//用户名
@property (nonatomic, strong)UILabel *userNamelabel;
//疾病
@property (nonatomic, strong)UILabel *diseaseLabel;
//就诊时间
@property (nonatomic, strong)UILabel *timeLabel;
//就诊状态视图
@property (nonatomic, strong)UIView *statusView;
//就诊状态
@property (nonatomic, strong)UILabel *statusLabel;

@end

@implementation PatientInfoCell

- (void)setStatuStr:(NSString *)statuStr{
    
    _statuStr = statuStr;
    self.statusLabel.text = statuStr;
    
}


#pragma mark
#pragma mark - 重写model
- (void)setModel:(DoctorApplyModel *)model{
    
    _model = model;
    
    self.userNamelabel.text = @"张先生";
    self.diseaseLabel.text = @"心理疾病";
    //时间
    NSDate *currentdate = [NSDate date];
    
    NSDateFormatter *fm = [[NSDateFormatter alloc] init];
    
    fm.dateFormat = @"MM-dd上午";
    
    NSString *dateString = [fm stringFromDate:currentdate];
    
    fm.dateFormat = @"HH";
    
    NSString *dateString2 = [fm stringFromDate:currentdate];
    
    fm.dateFormat = @"MM-dd下午";
    
    NSString *dateString3 = [fm stringFromDate:currentdate];
    
    
    if ([dateString2 intValue]>= 0 && [dateString2 intValue]<=12) {
        self.timeLabel.text = [NSString stringWithFormat:@"就诊时间:%@",dateString];
    }else{
        self.timeLabel.text = [NSString stringWithFormat:@"就诊时间:%@",dateString3];
    }
    
}

#pragma mark
#pragma mark - initWithStyle
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
        
    }
    
    return self;
    
}

#pragma mark
#pragma mark - 初始化界面
- (void)setupUI{
    
    //给控件赋值
    self.userNamelabel = [self addChildLabel];
    self.diseaseLabel = [self addChildLabel];
    self.timeLabel = [self addChildLabel];
    self.statusLabel = [self addChildLabel];
    
    //姓名字体大小 颜色
    self.userNamelabel.font = [UIFont systemFontOfSize:17];
    self.userNamelabel.textColor = [UIColor blackColor];
    //审核居中 颜色 字体大小
    self.statusLabel.textColor = [UIColor whiteColor];
    self.statusLabel.textAlignment = NSTextAlignmentCenter;
    self.statusLabel.font = [UIFont systemFontOfSize:17];
    
    //添加控件
    [self addSubview:self.userNamelabel];
    [self addSubview:self.diseaseLabel];
    [self addSubview:self.timeLabel];
    [self addSubview:self.userImageView];
    [self addSubview:self.statusView];
    [self.statusView addSubview:self.statusLabel];
    
    //添加约束
    [self.userImageView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(10);
        make.centerY.equalTo(self);
        make.height.equalTo(55);
        make.width.equalTo(55);
        
    }];
    
    [self.userNamelabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.userImageView.top);
        make.left.equalTo(self.userImageView.right).offset(20);
    }];
    
    [self.diseaseLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.userNamelabel.top);
        make.left.equalTo(self.userNamelabel.right).offset(10);
        
    }];
    
    [self.timeLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.userNamelabel.left);
        make.bottom.equalTo(self.userImageView.bottom);
    }];
    
    [self.statusView makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-20);
        make.centerY.equalTo(self);
        make.height.equalTo(60);
        make.width.equalTo(60);
    }];
    
    [self.statusLabel makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.statusView);
    }];
    
}

#pragma mark
#pragma mark - 创建label
- (UILabel *)addChildLabel{
    
    UILabel *lable = [[UILabel alloc] init];
    
    lable.textColor = [UIColor lightGrayColor];
    
    lable.font = [UIFont systemFontOfSize:15];
    
    [lable sizeToFit];
    
    return lable;
    
}

#pragma mark
#pragma mark - 重写userImageView get方法 设置头像
- (UIImageView *)userImageView{
    
    if (_userImageView == nil) {
        _userImageView = [[UIImageView alloc] init];
        
        _userImageView.image = [UIImage imageNamed:@"banner"];
    }
    
    return _userImageView;
    
}

#pragma mark
#pragma mark - 重写statusView get方法
-(UIView *)statusView{
    if (_statusView == nil) {
        _statusView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
        
        _statusView.backgroundColor = [UIColor colorWithRed:40 / 255.0 green:130 / 255.0 blue:180 / 255.0 alpha:1];
        
        //设置圆角
        _statusView.layer.cornerRadius = 30;
        
        _statusView.layer.masksToBounds = YES;
        
    }
    return _statusView;
}


@end
